import { $get, $post } from "./index";
import Taro from "@tarojs/taro";
import { DataResult } from '@/type'


export interface PriceAndTimeParam {
    /**
     * 起始地
     */
    strarea: string,
    /**
     * 类型
     */
    type: string,
    /**
     * 目的地
     */
    desarea: string,
}
//价格时效
export const priceAndTime = (data: PriceAndTimeParam) => {
    return $post<{ data: string }>("/selfmachine-system/order/priceAndTime", data);
};








export interface RecommendQueryParam {
    /**
     * 类型：接货/送货
     */
    carriagetype: string,
    /**
     * 省份名字
     */
    province: string,
    /**
     * 城市名字
     */
    city: string,
    /**
     * 详细地址
     */
    detailaddress?: string,
    /**
     * 地区
     */
    area?: string
}

// 获取推荐网点
export const getRecommandBranch = (data: RecommendQueryParam): Promise<Taro.request.SuccessCallbackResult<DataResult<any>>> => {
    return $get("/selfmachine-system/order/recommandBranch", data)
};



export interface LongPriceParam {
    /**
     * 到达地 省市区 中间用空格隔开
     */
    desarea: string,
    /**
     *  日期
     */
    senddate: string,
    /**
     * 起始地 省市区 中间用空格隔开
     */
    strarea: string,
    /**
     * 承运类型 
     */
    type: string,
    /**
     *  货物体积
     */
    volume: number,
    /** 
     *  货物重量
     */
    weight: number,
    number?: number,
    startCompany: string,
    descCompany: string
}
//长途运费
export const longsPrice = (data: LongPriceParam) => {
    return $post<{ data: string }>("/selfmachine-system/workerOrder/longPrice", data);
};


// 获取网点省市区
interface CompanyParams {
    showallbranchs: string
    showonlyTF: string
}
export const getCompany = (data: CompanyParams): Promise<Taro.request.SuccessCallbackResult<DataResult<any>>> => {
    return $get(`/selfmachine-system/addressBook/area/erp/${data.showallbranchs}/${data.showonlyTF}`)
}

// 获取网点省市区
export const getCompanyAddress = (data: string): Promise<Taro.request.SuccessCallbackResult<DataResult<any>>> => {
    return $get(`/selfmachine-system/addressBook/getByLocation/${data}`);
};







//合并工作人员端的

export interface GetCompanyDetailParam {
    /**
     * 用户id
     */
    customerCode: string,
    /**
     * 网点编号
     */
    branchCompanyNo: string,
}

// 网点详情
export const getCompanyDetail = (data: GetCompanyDetailParam): Promise<Taro.request.SuccessCallbackResult<DataResult<any>>> => {
    return $get("/selfmachine-system/WorkerCompany/particulars", data);
};


export interface LongPriceParam {
    /**
     * 到达地 省市区 中间用空格隔开
     */
    desarea: string,
    /**
     *  日期
     */
    senddate: string,
    /**
     * 起始地 省市区 中间用空格隔开
     */
    strarea: string,
    /**
     * 承运类型
     */
    type: string,
    /**
     *  货物体积
     */
    volume: number,
    /**
     *  货物重量
     */
    weight: number,
    number?: number,
    startCompany: string,
    descCompany: string
}

export interface CancelOrderParam {
    /**
     * 订单编号
     */
    ssoId: string,
}
//取消订单
export const cancelOrder = (data: CancelOrderParam) => {
    return $post("/selfmachine-system/workerOrder/cancelOrder", data);
};


export interface NewPayBillParam {
    /**
     * 承运单号集合
     */
    billNos: string[],
    /**
     * 自助机用户id
     */
    customerId?: string,
    /**
     * 打折前的金额
     */
    money: number,
    /**
     * 总金额
     */
    actualMoney: number,
    /**
     * 手续费
     */
    serviceCharge: number,
    /**
     * 自助机所在网点
     */
    btssId: number,
    /**
     * 支付所在设备 1、自助机 2、PC 3、公众号 4、其它
     */
    btssType: string,
}
export interface NewPayParam {
    /**
     * 单子信息
     */
    bill: NewPayBillParam,
    /**
     *
     */
    device_info: string,
    body: string,
    attach: string,
    /**
     * 总金额
     */
    total_fee: number,
    branchno: string,
    paytype: string,
    eop: string,
    type: string,
    /**
     * openId
     */
    v2?: string,
    v3: string,
    isdebug: string,
    debug: boolean,
}

// 支付链接
export const getPaySrc = (params: any) => {
    return $post("/selfmachine-system/fee/newPay", params);
};

// 支付回调
export const payResult = (data: any) => {
    return $get("/selfmachine-system/fee/pay/result", data, { noShowLoading: true })
}

export interface UpdateRemarksParam {
    /**
     * 订单编号
     */
    ssoId: string,
    authorizeUser: string
    authorizePhone: string
    verify: string
}

//改单 授权收货人
export const editOrderAuthorize = (data: UpdateRemarksParam[]) => {
    return $post("/selfmachine-system/editOrder/authorize", data);
};


export interface CustomerVerifyParam {
    /**
     * 手机号
     */
    phone: string,

}
//手机验证码 获取
export const customerVerify = (data: CustomerVerifyParam) => {
    return $get("/selfmachine-auth/customer/verify", data);
};

export interface UpdateRemarksParams {
    /**
     * 订单编号
     */
    ssoId: string,
    /**
     * 状态
     */
    isExamine: number,
}

// 审核数据
export const getAudit = (data: UpdateRemarksParams) => {
    return $post(`/selfmachine-system/order/updateRemarks`, data);
};


// 获取物流详情
// export const getLogisticsInfo = (data: string) => {
//     return $post("/selfmachine-system/logistics/getLogisticsInfo/" + data);
// };

/* 物流详情接口 */
export const getLogisticsInfo = (data) => {
    return $post("/selfmachine-system/logistics/getLogisticsInfo" , data);
};


// 获取订单信息
export const getOrderInfo = (params: string) => {
    return $get("/selfmachine-system//workerOrder/orderList", { billNo: params });
};

interface Verify {
    phone: string
    isFromSign: boolean
    verify?: string
}
// 获取验证码
export const getCodeNum = (data: Verify) => {
    return $get("/selfmachine-auth/customer/verify", data);
};





